<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery-2.1.0.js"></script>
</head>

<body>
    <form id="register">
        昵称：
        <input type="text" name="name"><br>
        密码：
        <input type="text" name="password"><br>
        头像
        <input type="file" name="img"><br>
        生日
        <input type="date" name="birthday" id="birthday"><br>
        性别：<br>
        <input type="radio" name="sex" value="男">男
        <input type="radio" name="sex" value="女">女 <br>
        <button id="register_btn"> 提交</button>
    </form>

    <script>
        $("#register_btn").click(function send(e) {
            e.preventDefault();
            $.ajax({
            type: "POST",
            url: "http://localhost:8080/register",
            processData: false,
            contentType: false,
            data:  new FormData($("#register")[0]),
            dataType: "json",
            success: function (response) {
                if( response.code != 200){
                    alert("注册失败")
                }else{
                    window.location.href="/login.html"
                }
            },
            error: function (response) {

            }
        });
            
        })
       
    </script>
</body>

</html>